Pressidian
花园入口
笔记
项目
关于
实验室
GitHub
花园入口
笔记
项目
关于
实验室
GitHub

KNOWLEDGE PATHS

笔记库
当前位置
笔记库/前端/三件套/样式/CSS/MDN文档/1 基础样式/5 调整大小

Test your skills: Sizing

12 分钟阅读 · Note

目录树 578 篇

                  • 在 CSS 中调整大小
                  • Test your skills: Sizing
          • tailwindCSS
      • 前端技术栈
    • 笔记目录
    • CLAUDE.md
    • Vue 组件与 Render 函数

关联笔记 6

↗在 CSS 中调整大小同一路径↗背景与边框共同主题↗测试你的技能:CSS 样式基础共同主题↗层叠、优先级与继承共同主题↗调试 CSS共同主题↗关系选择器共同主题
  • Test your skills: Sizing

Test your skills: Sizing

  • Previous
  • Overview: CSS styling basics
  • Next

The aim of this skill test is to help you assess whether you understand the different ways of sizing items in CSS.

Note: To get help, read our Test your skills usage guide. You can also reach out to us using one of our communication channels.

Sizing 1

In this task, you have two boxes.

To complete the task:

  1. Size the first box so that the height will be at least 100px, even if there is less content that would cause it to grow to that height. The content should not overflow if it doesn't fit into the box.
  2. To test this, remove the content from the HTML to make sure you still get a 100px tall box even with no content.
  3. Size the second box so that it is fixed at 100px tall. In this case, the content should overflow.

The starting point of the task looks like this:

Play

Here's the underlying code for this starting point:

htmlCopyPlay

<div class="box box1">
  <p>
    Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion
    daikon amaranth tatsoi tomatillo melon azuki bean garlic. Gumbo beet greens
    corn soko endive gumbo gourd.
  </p>
</div>

<div class="box box2">
  <p>
    Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion
    daikon amaranth tatsoi tomatillo melon azuki bean garlic. Gumbo beet greens
    corn soko endive gumbo gourd.
  </p>
</div>

cssCopyPlay

body {
  font: 1.2em / 1.5 sans-serif;
  padding: 1em;
}

.box {
  border: 5px solid black;
  width: 400px;
  margin-bottom: 1em;
}

.box1 {
  /* Add styles here */
}

.box2 {
  /* Add styles here */
}

The updated styling should look like this:

Play

Click here to show the solution

There are two boxes. The first one should be given a min-height so it expands to hold the additional content, but will not shrink below 100px tall if the content is removed. The second box is given a fixed height, which will cause content to overflow.

Sizing 2

In this task, you have a box that contains another box.

To complete the task:

  1. Make the inner box width 60% of the width of the outer box. The box-sizing property is set to border-box, which means that the total width includes any padding and border.
  2. Give the inner box 10% padding on all sides.

The starting point of the task looks like this:

Play

Here's the underlying code for this starting point:

htmlCopyPlay

<div class="box">
  <div class="inner">Make me 60% of my parent's width.</div>
</div>

cssCopyPlay

body {
  font: 1.2em / 1.5 sans-serif;
  padding: 1em;
}

.box {
  border: 5px solid black;
  width: 400px;
  margin-bottom: 1em;
}

.inner {
  background-color: rebeccapurple;
  color: white;
  border-radius: 5px;
}

* {
  box-sizing: border-box;
}
.inner {
  /* Add styles here */
}

The updated styling should look like this:

Play

Click here to show the solution

Set the box width to 60%, and give it a padding value of 10%. All elements already have box-sizing: border-box set to save you from worrying about calculating the 60% width value:

Sizing 3

In this task, you have two images in boxes. One image is smaller than the box, while the other is larger, causing it to break out of the box.

To complete the task, imagine that the box is responsive and therefore could grow and shrink. Apply a declaration to the images so that the large image shrinks down into the box, but the small image does not stretch.

The starting point of the task looks like this:

Play

Here's the underlying code for this starting point:

htmlCopyPlay

<div class="box">
  <img
    alt="A pink star"
    src="https://mdn.github.io/shared-assets/images/examples/star-pink_256x256.png" />
</div>

<div class="box">
  <img
    alt="Hot air balloons flying in clear sky, and a crowd of people in the foreground"
    src="https://mdn.github.io/shared-assets/images/examples/balloons.jpg" />
</div>

cssCopyPlay

body {
  font: 1.2em / 1.5 sans-serif;
  padding: 1em;
}
.box {
  border: 5px solid black;
  margin-bottom: 1em;
  width: 500px;
}

img {
  /* Add styles here */
}

The updated styling should look like this:

Play

Click here to show the solution

Set the images' max-width property to 100% to contain the large image inside its box. If you use width: 100%, the small image will stretch.

  • Previous
  • Overview: CSS styling basics
  • Next

Help improve MDN

Was this page helpful to you?

YesNo

Learn how to contribute

This page was last modified on Feb 3, 2026 by MDN contributors.

View this page on GitHub • Report a problem with this content

Filter sidebar

  1. Learn web development

  2. MDN curriculum

  3. Getting started modules

  4. Environment setup

  5. Your first website

  6. Web standards

  7. Soft skills

  8. Core modules

  9. Structuring content with HTML

  10. CSS styling basics

    1. What is CSS?
    2. CSS getting started
    3. Challenge: Biography page
    4. Basic selectors
    5. Attribute selectors
    6. Pseudo-classes and elements
    7. Combinators
    8. Test: Selectors
    9. Box model
    10. Test: Box model
    11. Handling conflicts
    12. Test: Cascade
    13. Challenge: Fixing blog styles
    14. Values and units
    15. Test: Values and units
    16. Sizing
    17. Test: Sizing
    18. Backgrounds and borders
    19. Test: Backgrounds and borders
    20. Overflow
    21. Test: Overflow
    22. Challenge: Sizing and decorating
    23. Images, media, forms
    24. Test: Images and forms
    25. Styling tables
    26. Challenge: Styling color scheme search
    27. Debugging CSS
    28. Test: Styling basics tests index
    29. Additional tutorials
  11. CSS text styling

  12. CSS layout

  13. Dynamic scripting with JavaScript

  14. JavaScript frameworks and libraries

  15. Accessibility

  16. Design for developers

  17. Version control

  18. Extension modules

  19. Advanced JavaScript objects

  20. Client-side web APIs

  21. Asynchronous JavaScript

  22. Web forms

  23. Understanding client-side tools

  24. Server-side websites

  25. Web performance

  26. Testing

  27. Further resources

  28. How to solve common problems

  29. About

  30. Resources for educators

  31. Changelog

MongoDB AtlasAd

Your blueprint for a better internet.

MDN

  • About
  • Blog
  • Mozilla careers
  • Advertise with us
  • MDN Plus
  • Product help

Contribute

  • MDN Community
  • Community resources
  • Writing guidelines
  • MDN Discord
  • MDN on GitHub

Developers

  • Web technologies
  • Learn web development
  • Guides
  • Tutorials
  • Glossary
  • Hacks blog

  • Website Privacy Notice
  • Telemetry Settings
  • Legal
  • Community Participation Guidelines

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.